package com.dubbo.pureprovider;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.dubbo.provider.service.DemoProviderService;
import com.dubbo.service.DemoApi;

/**
 * @author quanlong.chan
 * @Title: PureProvider
 * @Description:
 * @date 2019/7/31 18:36
 */
public class PureProvider {

    public static void main(String[] args) throws Exception {

        //服务实现todo SPI
        DemoProviderService demoProviderService = new DemoProviderService();

        // 当前应用配置
        ApplicationConfig application = new ApplicationConfig();
        application.setName("dubbo-demo-provider-02");

        // 连接注册中心配置
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("172.16.1.160");
        registry.setPort(2181);
        registry.setProtocol("zookeeper");

        // 服务提供者协议配置
        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(20881);
        protocol.setThreads(200);

        // 服务提供者暴露服务配置
        // 此实例很重，封装了与注册中心的连接，请自行缓存，否则可能造成内存和连接泄漏
        ServiceConfig<DemoApi> service = new ServiceConfig<>();
        service.setApplication(application);
        service.setRegistry(registry);
        service.setProtocol(protocol);
        service.setInterface(DemoApi.class);
        service.setRef(demoProviderService);

        // 暴露及注册服务
        service.export();

        System.in.read();
    }
}
